package com.soft.javase.day11.recursion;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/5/9
 */
public class DrinkBeer {
    public static void main(String[] args) {
        int money = 10;
        int initBeers = money / 2;
        int total = drinkBeer(initBeers, initBeers, initBeers);
        System.out.println("10元共可以喝 " + total + " 瓶啤酒");
    }

    public static int drinkBeer(int emptyBottles, int caps, int total) {
        int bottleBeers = emptyBottles / 2;
        int capBeers = caps / 4;

        int newBeers = bottleBeers + capBeers;

        if (newBeers == 0) {
            return total;
        }

        int newEmptyBottles = newBeers + (emptyBottles % 2);
        int newCaps = newBeers + (caps % 4);

        return drinkBeer(newEmptyBottles, newCaps, total + newBeers);
    }
}
